package com.znsb.msfq.push;

import android.content.Context;

import com.znsb.msfq.app.ZnsbApp;
import com.znsb.msfq.utils.LogUtils;

import java.util.Iterator;
import java.util.Set;

import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;

/**
 * @name： 孙科技
 * @phone： 13308334117
 * @createTime： 2017/2/23
 * @modifyTime： 2017/2/23
 * @explain：
 */
public class JPushUtils {
    public static JPushUtils jpush = null;

    public static JPushUtils getInstance() {
        if (jpush == null)
            jpush = new JPushUtils();

        return jpush;
    }

    public void setJPushAlias(String phone) {
        JPushInterface.setAliasAndTags(ZnsbApp.mContext, phone, null,
                mAliasTagCallback);
    }

    private static final String TAG = "JPush";
    private final TagAliasCallback mAliasTagCallback = new TagAliasCallback() {

        @Override
        public void gotResult(int code, String alias, Set<String> tags) {
            String logs;
            switch (code) {
                case 0:
                    logs = "Set tag and alias success" + code;
                    LogUtils.i(TAG, logs + "---" + alias);
                    break;

                case 6002:
                    logs = "Failed to set alias and tags due to timeout. Try again after 60s.";
                    LogUtils.i(TAG, logs);
                    break;

                default:
                    logs = "Failed with errorCode = " + code;
                    LogUtils.e(TAG, logs);
            }

        }
    };
}
